package phoenics.upservice.restcontroller.base;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import phoenics.common.BaseData.BaseErrorCode;
import phoenics.common.BaseData.RestResp;
import phoenics.common.BaseData.StatusData;
import phoenics.common.exception.AuthorizedException;
import phoenics.common.exception.BaseException;
import phoenics.common.exception.NotFoundException;
import phoenics.common.exception.ParamsException;
import phoenics.common.exception.StatusException;

import org.springframework.http.HttpStatus;

@RestControllerAdvice
public class BaseRestController {
	//private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BaseRestController.class);
	 @ExceptionHandler(value = {BaseException.class})
	 public RestResp handlerServerError(BaseException ex){
		 return RestResp.fail(ex.getMessage());
	 }
	 @ExceptionHandler(value = {AuthorizedException.class})
	 public RestResp handlerServerError(AuthorizedException ex){
		 return RestResp.fail(ex.getMessage());
	 }
	 @ExceptionHandler(value = {ParamsException.class})
	 public RestResp handlerServerError(ParamsException ex){
		 return RestResp.fail(ex.getMessage());
	 }
	 @ExceptionHandler(value = {StatusException.class})
	 public RestResp handlerServerError(StatusException ex){
		 return RestResp.fail(ex.getMessage());
	 }
	 @ExceptionHandler(value = {NotFoundException.class})
	 public RestResp handlerServerError(NotFoundException ex){
		 return RestResp.fail(ex.getMessage());
	 }
	 
	 @ExceptionHandler(value = {Exception.class})
	 public RestResp handlerServerError(Exception ex){
		 ex.printStackTrace();
		 return RestResp.fail(BaseErrorCode.SERVER_ERROR_MSG);
		 //return new StatusData(BaseErrorCode.SERVER_ERROR,BaseErrorCode.SERVER_ERROR_MSG);
	 }
}
